package com.petshop.test;

import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

@SpringBootTest
public class test {
    //定义一个初始时间，假设是2025.1.1.00:00时刻的秒数
    private static final long BEGIN_TIMESTAMP = 1735689600L;

    //付款时自动生成序列号pddId
    public static long getPddId(LocalDateTime beginTime) {
        //付款时间作为起始时间,计算pddId
        long nowSeconds = beginTime.toEpochSecond(ZoneOffset.UTC);
        return nowSeconds - BEGIN_TIMESTAMP;
    }

    public static boolean isExpired(Long pddId, LocalDateTime now) {
        //pddId的秒数
        long pddTime = pddId + BEGIN_TIMESTAMP;
        //付款后90天的秒数
        long endTime = pddTime + 90 * 24 * 60 * 60;
        //现在日期的秒数
        long nowSecond = now.toEpochSecond(ZoneOffset.UTC);
        if (nowSecond > endTime) {
            //已经过期返回false
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        long pddId = getPddId(LocalDateTime.now());
        boolean expired = isExpired(pddId, LocalDateTime.now());
        if (expired) {
            String binary = Long.toBinaryString(pddId);
            System.out.println("pdd::" + binary + "   长度为" + binary.length());
        } else {
            System.out.println("序列号已失效！");
        }
    }
}
